package org.pc2r.protocole.message;

import org.pc2r.protocole.EnumRequest;
import org.pc2r.protocole.RequestBuilder;

public class WelcomeConnectMessage extends Message {

	private String name;

	public WelcomeConnectMessage(EnumRequest request, String name) {
		super(request);

		assert (getType() == EnumRequest.CONNECT || getType() == EnumRequest.WELCOME) : request
				.toString();
		
		this.name = name;
	}

	public String getName() {
		return name;
	}

	@Override
  public int hashCode() {
    final int prime = 31;
    int result = super.hashCode();
    result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (!super.equals(obj))
      return false;
    if (getClass() != obj.getClass())
      return false;
    WelcomeConnectMessage other = (WelcomeConnectMessage) obj;
    if (this.name == null) {
      if (other.name != null)
        return false;
    } else if (!this.name.equals(other.name))
      return false;
    return true;
  }

  @Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append(getType());
		builder.append(RequestBuilder.SEPARATOR);
		builder.append(name);
		builder.append(RequestBuilder.SEPARATOR);
		builder.append(RequestBuilder.END);
		return builder.toString();
	}
	
	

}
